let SWDA_GoldWindow = {};

Window_Base.prototype.drawCurrencyValue = function (value, unit, wx, wy, ww) {
    this.changeTextColor('rgba(89, 186, 142, 1)');
    this.contents.fontSize = Yanfly.Param.GoldFontSize;
    wy = (this.height - this.contents.fontSize - this.padding * 2 - this.textPadding() * 2) / 2;

    if (this.usingGoldIcon(unit)) {
        var cx = Window_Base._iconWidth;
    } else {
        var cx = this.textWidth(unit);
    }
    var text = Yanfly.Util.toGroup(value);
    if (this.textWidth(text) > ww - cx) {
        text = Yanfly.Param.GoldOverlap;
    }
    this.setNumFontSize();
    this.drawText(text, cx + wx, wy, ww - cx - 4, 'right');
    this.resetFontSettings();

    if (this.usingGoldIcon(unit)) {
        this.drawIcon(Yanfly.Icon.Gold, wx, wy + 2);
    } else {
        this.changeTextColor(this.systemColor());
        this.drawText(unit, wx, wy, ww, 'right');
    }
    this.resetFontSettings();
};


//-----------------------------------------------------------------------------
// Window_Gold
//
// 重定义金钱窗口的类。

// 尺寸
Window_Gold.prototype.initialize = function (x, y) {
    const width = this.windowWidth();
    //var height = this.windowHeight();
    //this._goldWindow.width = 240;
    const height = 96;
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this.refresh();
};

// 显示文字
Window_Gold.prototype.refresh = function () {
    const x = this.textPadding();
    const width = this.contents.width - this.textPadding() * 2;
    this.contents.clear();
    this.drawCurrencyValue(this.value(), this.currencyUnit(), x, 0, width);


};

//-----------------------------------------------------------------------------
// 调整其它界面中金钱窗口的位置

SWDA_GoldWindow.Window_Message_CreateSubWindows = Window_Message.prototype.createSubWindows;
Window_Message.prototype.createSubWindows = function () {
    SWDA_GoldWindow.Window_Message_CreateSubWindows.call(this);
    this._goldWindow.x = Graphics.boxWidth -this._goldWindow.width - 64;
};
SWDA_GoldWindow.Window_Message_UpdatePlacement = Window_Message.prototype.updatePlacement;
Window_Message.prototype.updatePlacement = function() {
    SWDA_GoldWindow.Window_Message_UpdatePlacement.call(this);
    this._goldWindow.y = this.y > 0 ? 40 : Graphics.boxHeight - this._goldWindow.height - 40;
};
